/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//		File Name		:		CPayer.h
//
//		Author			:		Vindicated Games
//
//		Purpose			:		Encapsulate all functionality in the Player class
//
//		Dates			:		Written( Feb 15, 2011 ) by Vindicated Games		LastUpdate( March 3, 2011  ) by Jayson Wu
//	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "CPlayer.h"

#include "../SGD Wrappers/SGD_Math.h"
#include "../SGD Wrappers/CSGD_TextureManager.h"
#include "../SGD Wrappers/CSGD_DirectInput.h"
#include "../Managers/VIN_SoundManager.h"
#include "../Core/MessageSystem.h"
#include "../Core/CGame.h"
#include "../Game States/CGamePlayState.h"
#include "CMeleeEnemy.h"


CPlayer::CPlayer()
{
	m_nHealth = m_nMaxHealth = 5000;
	castleLevel = 1;
	SetGroundPt(0);
	currentImageID = MessageSystem::GetInstance()->GetStaticImageID(IMAGE_CASTLE1);
	SetHP(m_nHealth);
	SetPosX(530);
	SetPosY(145);
	SetWidth(256);
	SetHeight(256);
	SetType(OBJ_PLAYER);
	SetImageID(MessageSystem::GetInstance()->GetStaticImageID(IMAGE_CASTLE1));
	archerTimer = 0.0f;
	SetRect(&CastleRect, 530, 145, 786, 401);
}

CPlayer::~CPlayer()
{

}

void CPlayer::Render()
{
	//GetPosX();
	CSGD_TextureManager* pTM  = CSGD_TextureManager::GetInstance();
	CSGD_Direct3D*		pD3D = CSGD_Direct3D::GetInstance();

	if(castleLevel == 3)
	{
		pTM->Draw(GetCurrentID(),(int)GetPosX() - 88,(int)GetPosY(),1.5f, 1.5f);
	}
	else
		pTM->Draw(GetCurrentID(),(int)GetPosX(),(int)GetPosY(),1.5f, 1.5f);
}

RECT CPlayer::GetHealthRect()
{
	return CastleRect;
}

bool CPlayer::Input()
{
	return true;
}

void CPlayer::Update(float fElapsedTime)
{
	archerTimer -= fElapsedTime;

	SetPosX(530);
	SetPosY(145);

	/*SetVelX(0);
	SetVelY(0);*/
	if(GetHP() <= 0 )
	{
		// Castle HP is 0 Castle IS DEAD!!!
	}

	//if(castleLevel == 2)
	//{
	//	if(archerTimer < 0)
	//	{
	//		float tempOffset = rand()%20;
	//		MessageSystem::GetInstance()->SendNewMessage(new CCreateProjectileMessage(520.0f, 280.0f, -50.0f, -1.0f*tempOffset, 2));
	//		archerTimer = (float)(rand()%30)*0.1f;
	//	}
	//}
	//else if(castleLevel == 3)
	//{
	//	if(archerTimer < 0)
	//	{
	//		float tempOffset = rand()%20;
	//		MessageSystem::GetInstance()->SendNewMessage(new CCreateProjectileMessage(520.0f, 280.0f, -60.0f, -1.0f*tempOffset, 2));
	//		archerTimer = (float)(rand()%10)*0.1f;
	//	}
	//}

	//CBaseObject::Update( fElapsedTime );

	////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

void CPlayer::UpgradeCastle()
{
	if(castleLevel == 1)
	{
		castleLevel++;
		SetHP(GetHP() + 1500);
		m_nMaxHealth = GetHP();
		currentImageID = MessageSystem::GetInstance()->GetStaticImageID(IMAGE_CASTLE2);
		MessageSystem::GetInstance()->SendNewMessage(new CCreateParticleEmitterMessage(GetPosX() + (GetWidth()*0.5f) - 16, GetPosY() + (GetHeight()) + 32, 0.0f, 0.0f, 1));
		VIN_SoundManager::GetInstance()->PlayCastleup();
	}
	else if(castleLevel == 2)
	{
		castleLevel++;
		SetHP(GetHP() + 3000);
		m_nMaxHealth = GetHP();
		SetPosX(320);
		currentImageID = MessageSystem::GetInstance()->GetStaticImageID(IMAGE_CASTLE3);
		MessageSystem::GetInstance()->SendNewMessage(new CCreateParticleEmitterMessage(GetPosX() + (GetWidth() + 50), GetPosY() + (GetHeight()) + 32, 0.0f, 0.0f, 1));
		//MessageSystem::GetInstance()->SendNewMessage(new CCreateParticleEmitterMessage(400.0f, 0.0f, 0.0f, 0.0f, 2));
	}
}

bool CPlayer::CheckCollision( IBaseInterface* pBase )
{
	return false;
}

void CPlayer::ResetPlayer()
{
	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();
	// Resets all the stats of the Player
	SetHeight(pTM->GetTextureHeight(GetCurrentID()));
	SetWidth(pTM->GetTextureHeight(GetCurrentID()));
	SetPosX(530);
	castleLevel = 1;
	SetPosY(280);
	SetType(OBJ_PLAYER);
	SetMaxHealth(5000);
	SetCash(0);
	SetHP(m_nMaxHealth);
}
